//筛选列表
function leftNav(){
	$('.filter2').hide();
	$('.filter1').animate({height: 'toggle'});
}
function rightNav() {
	$('.filter2').animate({height: 'toggle'});
	$('.filter1').hide();
}

//趋势图
function mAnalystTrend(id,data){
    return new Highcharts.Chart({
        chart: {
        	renderTo: id,
            type: "areaspline",
            spacing: [0, 0, 0, 0],
            backgroundColor: {
                linearGradient: [0, 0, 500, 500],
                stops: [
                    [0, 'rgb(23,25,34)'],
                    [1, 'rgb(23,25,34)']
                ]
            }
        },
        title: {
            text: null
        },
        colors:['#ffc766'],
        legend: {
            enabled: false
        },
        credits: {
            enabled: false
        },
        exporting: {
            enabled:false
        },
        xAxis: {
            gridLineWidth: 0,
            tickLength: 0,
            labels: {
                enabled: !1
            },
            title: {
                text: null
            },
            lineWidth: 0,
            tickInterval: 1,
            lineColor: "#cccccc",
            gridLineColor: "#f0f0f0",
            categories:data[0]
        },
        tooltip: {
            style: {
                color: "white",
                padding: "4px"
            },
            borderWidth: 0,
            shadow: !1,
            backgroundColor: "rgba(34,34,34, 0.6)",
            shared: !0,
            formatter: function() {
                return '<span style="color:' + (this.y >= 0 ? "#00ffa3" : "#ff846b") + '">盈亏点位' + this.y + "</span>"
            }
        },
        yAxis: {
            gridLineWidth: 0,
            tickLength: 0,
            labels: {
                enabled: !1
            },
            title: {
                text: null
            },
            tickInterval: 1,
            lineColor: "#cccccc",
            gridLineColor: "#f0f0f0"
        },
        plotOptions: {
            areaspline: {
            	fillColor : "#171922",
                marker: {
                    radius: 0,
                    fillColor: "white",
                    lineWidth: 0.5,
                    lineColor: "#171922"
                },
                lineWidth: 2,
                threshold: null
            },
            series: {
                lineColor: "#f73c42",
                point: {},
                stops: [
                        [0, "#fc951a"],
                        [1, Highcharts.Color("#f73c42").setOpacity(0).get('rgba')]
                    ]
            },
        },
        series: [{
            name: '',
            data: data[1]
        }]
                 
    })
}

//收缩分析师详情
function kaiDetails(obj){
	$(obj).parent().siblings('.l_master_detail').animate({height: 'toggle'});
}
//选择正向、反向订阅
var myAttr;
$(function() {
	$('.follow_btn .bor span').click(function() {
		$(this).attr({'class':'current'}).parents('div').siblings().find('span').attr({'class':''});
		direction = $(this).attr({'class':'current'}).attr('myAttr');
	})
})
//移除确定和取消按钮点击事件
function cancle(){
	$('.follow_btn').hide();
	window.setTimeout(window.location.reload(),2000);
}
function sure(obj){
	var eleAttr1 = $('.follow_btn .bor span').eq(0).attr('class');
	var eleAttr2 = $('.follow_btn .bor span').eq(1).attr('class');
	var isChecked = $(".squar input[type='checkbox']").is(':checked');
	if(direction == '0') { //正向订阅
		direction == 0;
	}else if(direction == '1'){ //反向订阅
		direction == 1;
	}
    status = 1;
	if(eleAttr1 == 'current' && isChecked || eleAttr2 == 'current' && isChecked) {
		$.ajax({
	        url:  gotofllow,
	        type: 'post',
	        data: {'analystid':aid,'analystname':analyst_username,'status':status,'direction':direction},
	        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
	        dataType:'json',
	        success: function(res){
	            if(res.status == 0){
	                //订阅失败
	                showTips();
	                $('.l_tips').html('订阅失败');
	                window.setTimeout(window.location.reload(),2000);
	            }else if(res.status == 2){
	                //用户未登录
	                showTips();
	                $('.l_tips').html('请先登录');
	                setTimeout(function(){
	                	window.location.href = gotologin;
	                },2000)
	            }else if(res.status == 3){
	                //用户未登录
	                showTips();
	                $('.l_tips').html('订阅已达上限');
	                window.setTimeout(window.location.reload(),2000);
	            }else{
	                //订阅成功
	                showTips();
	                $('.l_tips').html('订阅成功');
	                window.setTimeout(window.location.reload(),2000);
	            }
	        }
	    });
		$('.follow_btn').hide();
	}else if(eleAttr1 == '' && eleAttr2 == '' && !isChecked) {
		showTips();
        $('.l_tips').html('选择方向和协议');
        hideTips();
        return false;
	}else if(eleAttr1 == 'current'  && !isChecked || eleAttr2 == 'current' && !isChecked) {
		showTips();
        $('.l_tips').html('选择协议');
        hideTips();
        return false;
	}else {
		showTips();
        $('.l_tips').html('选择方向');
        hideTips();
        return false;
	}
}
//取消订阅
function follow(status,direction,obj){
    var isChecked = $(".squar input[type='checkbox']").is(':checked');
	if(!isChecked) {
		showTips();
        $('.l_tips').html('请勾选协议');
		$('.follow_btn').show();
		hideTips();
	}else{
        $(obj).removeAttr('onclick');
        $.ajax({
            url:gotofllow,
            type: 'post',
            data: {'analystid':aid,'analystname':analyst_username,'status':status,'direction':direction},
            headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
            dataType:'json',
            success: function(res){
                if(res.status == 0){
                    //订阅失败
                    showTips();
                    $('.l_tips').html('订阅失败');
                    window.location.reload();
                }else if(res.status == 2){
                    //用户未登录
                    showTips();
                    $('.l_tips').html('请先登录');
                    setTimeout(function(){
                    	window.location.href = gotologin;
                    },2000)
                }else if(res.status == 3){
                    //用户未登录
                    showTips();
                    $('.l_tips').html('订阅已达上限');
                    window.setTimeout(window.location.reload(),2000);
                }else{
                    //订阅成功
                    showTips();
                    $('.l_tips').html('操作成功');
                    window.location.reload();
                }
            }
        });
    }
}
//搜索按钮
$(function() {
	$(".l_search").on('click',function(event){
		event.stopPropagation();
		$('.search_main').animate({width: 'toggle'});
	})
	$(".search_main").on('click',function(event){
		event.stopPropagation();
	})
})
//点击非搜索弹框部分，搜索弹框隐藏
$(document).on('click',function(){
	if($('.search_main').css('display') == 'block') {
        $('.search_main').hide();
    }
})
//搜索弹框重置按钮
function resetl(grade,bdtype,type) {
	var searchTxt = $('.search_txt').val('');
	window.location.href= bdlists+'?grade='+grade+'&bdtype='+bdtype+'&type='+type+'&searchname=';
}
//搜索弹框搜索按钮
function searched() {
	var searchTxt = $('.search_txt').val();
	event.preventDefault();
	$('#search-form').submit();
}
//导航搜索
function totle(grade,bdtype,type,searchname) {
	window.location.href= bdlists+'?grade='+grade+'&bdtype='+bdtype+'&type='+type+'&searchname='+searchname;
}
// 总收益曲线图
function profitChart(id,data){
    var t = this;
    return new Highcharts.Chart({
        chart: {
            renderTo: id,
            type: "areaspline",
            zoomType: "xy",
            pinchType:'',// 让在移动端可以滑动
            backgroundColor: '#171922',
            height: 150
        },
        title: {
            text: null
        },
        colors: ["#ffc766"],
        legend: {
            enabled: false
        },
        credits: {
            enabled: false
        },
        exporting: {
            enabled:false
        },
        xAxis: {
            gridLineWidth: 0,
            lineColor: "#2E303E",
            tickColor: "#2E303E",
            gridLineColor: "#2E303E",
            categories:data[0],
            tickInterval: Math.ceil(data[0].length / 7),
            labels: {
                rotation: false,
            }
        },
        yAxis: {
                opposite: true, //Y轴在右侧
            gridLineWidth: 0.5,
            lineColor: "#2E303E",
            tickColor: "#2E303E",
            gridLineColor: "#22242f",
            title: {
                text: null
            },
            labels: {
            }
        },
        tooltip: {
            style: {
                color: "white"
            },
            borderWidth: 0,
            shadow: !1,
            backgroundColor: "rgba(34,34,34, 0.6)",
            shared: !0
        },
        plotOptions: {
            areaspline: {
                fillColor: {
                    linearGradient: {
                        x1: 0,
                        y1: 0,
                        x2: 0,
                        y2: 1
                    },
                    stops: [
                        [0, "#3b9ce0"],
                        [1, Highcharts.Color("#3b9ce0").setOpacity(0).get('rgba')]
                    ]
                },
                marker: {
                    radius: 0,
                    fillColor: "white",
                    lineWidth: 1,
                    lineColor: "#ffc766"
                },
                lineWidth: 1,
                states: {
                    hover: {
                        lineWidth: 1
                    }
                },
                threshold: null
            },
            series: {
                lineColor: "#3b9ce0"
            }
        },
        series: [{
            name: "盈利点位",
            data: data[1]
        }]
    })
}
